package com.solocredit.finance.ui.main.adapter

import android.graphics.Color
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.solocredit.finance.R
import com.solocredit.finance.base.adapter.MullaRecyclerViewAdapter
import com.solocredit.finance.base.adapter.MullaViewHolderHelper
import org.json.JSONObject

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/7/26 16:42
 * @Annotation：Tab适配器
 */

class MullaTabAdapter(recyclerView: RecyclerView?) : MullaRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_mulla_tab) {
    override fun setItemChildListener(helper: MullaViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout) //点击Item
    }

    override fun fillData(helper: MullaViewHolderHelper, position: Int, model: JSONObject) {
        val textTab = helper.getTextView(R.id.textTab)
        textTab.text = model.optString("tabTitle")
        val imgNormal = helper.getImageView(R.id.imgNormal)
        val imgSelected = helper.getImageView(R.id.imgSelected)
        imgNormal.setImageResource(model.optInt("tabImageNormal"))
        imgSelected.setImageResource(model.optInt("tabImageSelected"))
        when(model.optBoolean("isSelect", false)){
            true -> {
                imgNormal.visibility = View.GONE
                imgSelected.visibility = View.VISIBLE
                textTab.setTextColor(Color.parseColor("#FF000000"))
            }
            else -> {
                imgNormal.visibility = View.VISIBLE
                imgSelected.visibility = View.GONE
                textTab.setTextColor(Color.parseColor("#FFC4C4C4"))
            }
        }
    }
}